﻿namespace EasyCMS.Core.Dals.Category
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using Pismire;
    using Pismire.Data;

    public class SqlServer2005 : Sql2005DalBase, ICategory
    {
        #region ICategory 成员

        List<EasyCMS.Common.DataComponents.Category> ICategory.GetCategoryDataTable()
        {
            //初始化定义
            List<EasyCMS.Common.DataComponents.Category> dataList = new List<EasyCMS.Common.DataComponents.Category>();
            //recordCount = 0;

            //打开连接连接
            dcm.Open();

            //
            IDataReader reader = null;

            try
            {
                SqlCommand cmd = GetSqlCmd();
                cmd.CommandText = "select * from [Categorys]";
                cmd.CommandType = CommandType.Text;

                //execute
                reader = cmd.ExecuteReader();

                //
                if (reader != null)
                {
                    DataPopulater<EasyCMS.Common.DataComponents.Category> builder = DataPopulater<EasyCMS.Common.DataComponents.Category>.CreatePopulater(reader);

                    while (reader.Read())
                    {
                        dataList.Add(builder.Populate(reader));
                    }
                }
            }
            catch (Exception ex)
            {
                //异常记日志
                throw ex;
            }
            finally
            {
                //关闭reader
                if (reader != null)
                {
                    if (!reader.IsClosed) reader.Close();
                    reader.Dispose();
                    reader = null;
                }

                //通知连接管理器关闭数据库连接
                dcm.Close();
            }

            //
            return dataList;
        }

        ExcuteState ICategory.Add(ref EasyCMS.Common.DataComponents.Category category)
        {
            throw new NotImplementedException();
        }

        ExcuteState ICategory.Update(ref EasyCMS.Common.DataComponents.Category category)
        {
            throw new NotImplementedException();
        }

        ExcuteState ICategory.Delete(int id)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
